package com.hsmpay.mobile.service.other.impl;

import com.hsmpay.common.service.impl.BaseServiceSupport;
import com.hsmpay.mobile.dao.other.SettingsDao;
import com.hsmpay.mobile.pojo.other.Settings;
import com.hsmpay.mobile.service.other.SettingsService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.SQLException;

@Service("settingsService")
public class SettingsServiceImpl<Entity extends Settings,Query extends Object> extends BaseServiceSupport<Entity,Query> implements SettingsService<Entity,Query> {
    @Resource(name="settingsDao")
    private SettingsDao<Settings,Long> settingsDao;

    /**
     * 根据key获取对象
     * @param functionKey
     * @return
     * @throws SQLException
     */
    public Settings getSettingsByFk(String functionKey) throws SQLException {
        Settings settings = new Settings();
        settings.setFunctionKey(functionKey);
        settings = settingsDao.searchEntity(settings);
        return settings;
    }

    /**
     * 根据key获取mainValue
     * @param functionKey
     * @return
     * @throws SQLException
     */
    public String getMainValueByFk(String functionKey) throws SQLException {
        Settings settings = new Settings();
        settings.setFunctionKey(functionKey);
        settings = settingsDao.searchEntity(settings);
        return settings == null?null:settings.getMainValue();
    }
}
